/*
 * Copyright (C) 2010 LianHaidong <lianhaidong@gmail.com>
 */

#ifndef _UTILS_MEM_DBG_H
#define _UTILS_MEM_DBG_H

struct mem_entry;
struct mem_dbg_pos {
	char *alloc_file;
	char *free_file;
	int alloc_pos;
	int free_pos;
	struct mem_entry *me;
};

struct mem_entry {
	struct list_head entry;
	int count;
	struct list_head pos_list;
	uint32_t magic;
};

#define MEM_ENTRY_MAGIC 0XABCDEF
#define MEM_ENTRY_SET_MAGIC(me) ((me)->magic = MEM_ENTRY_MAGIC)
#define MEM_ENTRY_VALID(me) ((me)->magic == MEM_ENTRY_MAGIC)

void mem_entry_show_all(int fd);

void *mem_alloc(int size, char *file, int line);

int mem_free(void *entry, char *file, int line);

#define malloc(size) mem_alloc(size, __FILE__, __LINE__)
#define free(entry) mem_free(entry, __FILE__, __LINE__)

#endif	/* _UTILS_MEM_DBG_H */
